package com.sinosoft.vaccinetoai.server.business.chatrecord.coverter;

import com.sinosoft.vaccinetoai.common.CommonConstants;
import com.sinosoft.vaccinetoai.dao.po.business.ChatRecord;
import com.sinosoft.vaccinetoai.security.utils.SecurityUtils;
import com.sinosoft.vaccinetoai.server.business.chatrecord.addchatrecord.io.AddChatRecordIO;
import com.sinosoft.vaccinetoai.utils.IdUtils;
import org.springframework.util.CollectionUtils;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author xiazhihao
 * @ClassName: ChatRecordConverter
 * @ClassNameExplain:
 * @Description:
 * @date 2023/12/18 21:56
 */
public class ChatRecordConverter {

    private ChatRecordConverter(){

    }

    public static ChatRecord covertChatRecord(AddChatRecordIO addChatRecordIO){
        if (Objects.isNull(addChatRecordIO)){
            return null;
        }
        ChatRecord chatRecord = new ChatRecord();
        chatRecord.setId(IdUtils.generateId(CommonConstants.ID_GEN_KEY_COMMON));
        chatRecord.setChainRecordId(addChatRecordIO.getChainRecordId());
        chatRecord.setText(addChatRecordIO.getText());
        chatRecord.setImages(addChatRecordIO.getImages());
        chatRecord.setConversationOptions(addChatRecordIO.getConversationOptions());
        chatRecord.setType(addChatRecordIO.getType());
        //设置用户id
        chatRecord.setUserId(SecurityUtils.getPrincipal().getUserId());
        chatRecord.setRequestOptions(addChatRecordIO.getRequestOptions());
        chatRecord.setInversion(addChatRecordIO.getInversion());
        chatRecord.setExtra(addChatRecordIO.getExtra());
        //时间设置
        chatRecord.setCreateTime(new Date());
        chatRecord.setUpdateTime(new Date());
        return chatRecord;
    }

    public static List<ChatRecord> covertChatRecords(List<AddChatRecordIO> addChatRecordIOList){
        if (CollectionUtils.isEmpty(addChatRecordIOList)){
            return Collections.emptyList();
        }
        return addChatRecordIOList.stream().map(ChatRecordConverter::covertChatRecord).collect(Collectors.toList());
    }

}
